Fix unit test failures not failing the build#33423
Merged
Conversation
The issue was in run-dotnet-preview.yml where when useExitCodeForErrors=true and tests failed, the script would: 1. Log an error message 2. Mark the task as Failed 3. Exit with code 0 (success) This caused builds to report 'succeededWithIssues' instead of 'failed', allowing PRs to pass even with failing unit tests. Changed exit 0 to exit $LASTEXITCODE to properly propagate the test failure exit code, ensuring the build actually fails when tests fail. Fixes #33391
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug where unit test failures were not properly failing the Azure DevOps build pipeline. The issue was that when tests failed, the pipeline would exit with code 0 (success) despite logging errors, causing builds to pass with failing tests.
Key Changes:
- Changed exit code from hardcoded
0to$LASTEXITCODEto properly propagate test failure codes - Ensures pipeline jobs fail correctly when
useExitCodeForErrors: trueis set
Member
|
Do we want this? was not the problem this is comment out ? |
Member
Author
|
@rmarinho I think we should have either one of these. Right now failing unit tests go undetected unless you go look at Azure DevOps so I don't think we want that. Do we know the reason why that was commented out? |
rmarinho
approved these changes
Jan 13, 2026
kubaflo
pushed a commit
to kubaflo/maui
that referenced
this pull request
Jan 16, 2026
> [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ## Description This PR fixes a critical issue where unit test failures were not properly failing the build pipeline, allowing PRs to pass CI checks even when tests failed. ## Problem In `/eng/pipelines/common/run-dotnet-preview.yml` at line 58, when `useExitCodeForErrors: true` is set and tests fail, the script was: 1. ✅ Logging an error message 2. ✅ Marking the task as "Failed" using Azure DevOps logging commands 3. ❌ **Exiting with code 0 (success)** This caused jobs to show as `succeededWithIssues` instead of `failed`, and overall PR checks would pass even though unit tests failed. ### Example PR dotnet#33391 had failing unit tests: - Controls.Xaml.UnitTests failed with "Test suite had 1 failure(s)" - Build timeline showed `"result": "succeededWithIssues"` - But overall check status was SUCCESS ✅ ## Solution Changed line 58 from: ```powershell exit 0 ``` to: ```powershell exit $LASTEXITCODE ``` This ensures the PowerShell script exits with the actual failure code from the test run, properly failing the build pipeline. ## Impact After this change: - ✅ Unit test failures will properly fail the build - ✅ PR checks will show as failed when tests fail - ✅ Build status will accurately reflect test results - ✅ No more false positives where builds pass with failing tests ## Testing This fix will be validated by observing the build behavior on this PR itself. The change is minimal and surgical - only affecting the exit code propagation when tests fail.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description
This PR fixes a critical issue where unit test failures were not properly failing the build pipeline, allowing PRs to pass CI checks even when tests failed.
Problem
In
/eng/pipelines/common/run-dotnet-preview.ymlat line 58, whenuseExitCodeForErrors: trueis set and tests fail, the script was:This caused jobs to show as
succeededWithIssuesinstead offailed, and overall PR checks would pass even though unit tests failed.Example
PR #33391 had failing unit tests:
"result": "succeededWithIssues"Solution
Changed line 58 from:
to:
This ensures the PowerShell script exits with the actual failure code from the test run, properly failing the build pipeline.
Impact
After this change:
Testing
This fix will be validated by observing the build behavior on this PR itself. The change is minimal and surgical - only affecting the exit code propagation when tests fail.